﻿///<reference path="../lib/lt_tsbb.d.ts"/>
///<reference path="../lib/blockViews/FlowView.ts"/>
///<reference path="../localsave/localsave.ts"/>

class MyBlock implements lighttool.tsbb.IBBAction_Flow
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
    }
    setInParmaValues(values: any[]): void
    {
    }
    getOutParamValue(index: number): any
    {
        if (index == 0)
            return 100;
        return null;
    }
    getOutParamValues(): any[]
    {
        return [100];
    }

    //行为组
    waitcount: number = 0;
    text: HTMLAnchorElement;
    onInit(): void //进入状态
    {
        var content = document.getElementById("content");
        this.text = document.createElement("a");
        this.text.text = "当前块" + this.desc.name;
        content.appendChild(this.text);

        this.waitcount = 50;
    }
    onExit(): void //离开状态
    {

    }

    getExitState(): number
    {
        if (this.waitcount <= 0)
            return 1;//0号出口
        return -1;//没处理完
    }

    onUpdate(): void//表达式计算
    {
        this.text.text = "当前块" + this.desc.name + "倒计时" + this.waitcount;
        this.waitcount--;
    }

    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "myblock";
        desc.exitNames = ["出口0", "出口1", "出口2", "出口3"];
        desc.inParamNames = ["number", "name"];
        desc.inParamTypes = ["integer", "string"];
        desc.outParamNames = ["number", "number"];
        desc.outParamTypes = ["integer", "integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new MyBlock(); } });
    }
}
class MyBlock2 implements lighttool.tsbb.IBBAction_Flow
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0];
    }
    getOutParamValue(index: number): any
    {
        return null;
    }
    getOutParamValues(): any[]
    {
        return [];
    }

    //行为组
    waitcount: number = 0;
    text: HTMLAnchorElement;
    value: number = 0;
    onInit(): void //进入状态
    {
        var content = document.getElementById("content");

        var text2 = document.createElement("a");
        text2.text = " 我需要参数100:" + this.value;
        content.appendChild(text2);

        this.text = document.createElement("a");
        this.text.text = "  当前块" + this.desc.name + " 我需要参数100:" + this.value;
        content.appendChild(this.text);

        this.waitcount = 50;
    }
    onExit(): void //离开状态
    {

    }

    getExitState(): number
    {
        if (this.waitcount <= 0)
            return 0;//0号出口
        return -1;//没处理完
    }

    onUpdate(): void//表达式计算
    {
        this.text.text = "当前块" + this.desc.name + "倒计时" + this.waitcount;
        this.waitcount--;
    }

    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "myblock2";
        desc.exitNames = ["出口0"];
        desc.inParamNames = ["number", "number"];
        desc.inParamTypes = ["integer", "integer"];
        desc.outParamNames = ["number", "test"];
        desc.outParamTypes = ["integer", "integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new MyBlock2(); } });
    }
}
class MyBlock3 implements lighttool.tsbb.IBBAction_Flow
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0];
    }
    getOutParamValue(index: number): any
    {
        return null;
    }
    getOutParamValues(): any[]
    {
        return [];
    }

    //行为组
    waitcount: number = 0;
    text: HTMLAnchorElement;
    value: number = 0;
    onInit(): void //进入状态
    {
        var content = document.getElementById("content");

        var text2 = document.createElement("a");
        text2.text = " 我需要参数100:" + this.value;
        content.appendChild(text2);

        this.text = document.createElement("a");
        this.text.text = "  当前块" + this.desc.name + " 我需要参数100:" + this.value;
        content.appendChild(this.text);

        this.waitcount = 50;
    }
    onExit(): void //离开状态
    {

    }

    getExitState(): number
    {
        if (this.waitcount <= 0)
            return 0;//0号出口
        return -1;//没处理完
    }

    onUpdate(): void//表达式计算
    {
        this.text.text = "当前块" + this.desc.name + "倒计时" + this.waitcount;
        this.waitcount--;
    }

    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "myblock3";
        desc.exitNames = ["出口0", "出口1", "出口2", "出口3"];
        desc.inParamNames = ["number", "name", "number"];
        desc.inParamTypes = ["integer", "string", "stirng"];
        desc.outParamNames = ["number", "number", "number"];
        desc.outParamTypes = ["integer", "integer", "integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new MyBlock2(); } });
    }
}
class MyBlock4 implements lighttool.tsbb.IBBAction_Flow
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0];
    }
    getOutParamValue(index: number): any
    {
        return null;
    }
    getOutParamValues(): any[]
    {
        return [];
    }

    //行为组
    waitcount: number = 0;
    text: HTMLAnchorElement;
    value: number = 0;
    onInit(): void //进入状态
    {
        var content = document.getElementById("content");

        var text2 = document.createElement("a");
        text2.text = " 我需要参数100:" + this.value;
        content.appendChild(text2);

        this.text = document.createElement("a");
        this.text.text = "  当前块" + this.desc.name + " 我需要参数100:" + this.value;
        content.appendChild(this.text);

        this.waitcount = 50;
    }
    onExit(): void //离开状态
    {

    }

    getExitState(): number
    {
        if (this.waitcount <= 0)
            return 0;//0号出口
        return -1;//没处理完
    }

    onUpdate(): void//表达式计算
    {
        this.text.text = "当前块" + this.desc.name + "倒计时" + this.waitcount;
        this.waitcount--;
    }

    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "myblock4";
        desc.exitNames = ["出口0"];
        desc.inParamNames = ["number", "name", "number"];
        desc.inParamTypes = ["integer", "string", "stirng"];
        desc.outParamNames = ["number", "number", "number"];
        desc.outParamTypes = ["integer", "integer", "integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new MyBlock2(); } });
    }
}
class MyBlock5 implements lighttool.tsbb.IBBAction_Flow
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0];
    }
    getOutParamValue(index: number): any
    {
        return null;
    }
    getOutParamValues(): any[]
    {
        return [];
    }

    //行为组
    waitcount: number = 0;
    text: HTMLAnchorElement;
    value: number = 0;
    onInit(): void //进入状态
    {
        var content = document.getElementById("content");

        var text2 = document.createElement("a");
        text2.text = " 我需要参数100:" + this.value;
        content.appendChild(text2);

        this.text = document.createElement("a");
        this.text.text = "  当前块" + this.desc.name + " 我需要参数100:" + this.value;
        content.appendChild(this.text);

        this.waitcount = 50;
    }
    onExit(): void //离开状态
    {

    }

    getExitState(): number
    {
        if (this.waitcount <= 0)
            return 0;//0号出口
        return -1;//没处理完
    }

    onUpdate(): void//表达式计算
    {
        this.text.text = "当前块" + this.desc.name + "倒计时" + this.waitcount;
        this.waitcount--;
    }

    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "myblock5";
        desc.exitNames = ["出口0", "出口1", "出口2", "出口3"];
        desc.inParamNames = ["number", "name", "number"];
        desc.inParamTypes = ["integer", "string", "stirng"];
        desc.outParamNames = ["number", "number", "number"];
        desc.outParamTypes = ["integer", "integer", "integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new MyBlock2(); } });
    }
}
class MyBlock6 implements lighttool.tsbb.IBBAction_Flow
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0];
    }
    getOutParamValue(index: number): any
    {
        return null;
    }
    getOutParamValues(): any[]
    {
        return [];
    }

    //行为组
    waitcount: number = 0;
    text: HTMLAnchorElement;
    value: number = 0;
    onInit(): void //进入状态
    {
        var content = document.getElementById("content");

        var text2 = document.createElement("a");
        text2.text = " 我需要参数100:" + this.value;
        content.appendChild(text2);

        this.text = document.createElement("a");
        this.text.text = "  当前块" + this.desc.name + " 我需要参数100:" + this.value;
        content.appendChild(this.text);

        this.waitcount = 50;
    }
    onExit(): void //离开状态
    {

    }

    getExitState(): number
    {
        if (this.waitcount <= 0)
            return 0;//0号出口
        return -1;//没处理完
    }

    onUpdate(): void//表达式计算
    {
        this.text.text = "当前块" + this.desc.name + "倒计时" + this.waitcount;
        this.waitcount--;
    }

    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "myblock6";
        desc.exitNames = ["出口0", "出口1", "出口2", "出口3"];
        desc.inParamNames = ["number", "name", "number"];
        desc.inParamTypes = ["integer", "string", "stirng"];
        desc.outParamNames = ["number", "number", "number"];
        desc.outParamTypes = ["integer", "integer", "integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new MyBlock2(); } });
    }
}
class MyBlock7 implements lighttool.tsbb.IBBAction_Flow
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0];
    }
    getOutParamValue(index: number): any
    {
        return null;
    }
    getOutParamValues(): any[]
    {
        return [];
    }

    //行为组
    waitcount: number = 0;
    text: HTMLAnchorElement;
    value: number = 0;
    onInit(): void //进入状态
    {
        var content = document.getElementById("content");

        var text2 = document.createElement("a");
        text2.text = " 我需要参数100:" + this.value;
        content.appendChild(text2);

        this.text = document.createElement("a");
        this.text.text = "  当前块" + this.desc.name + " 我需要参数100:" + this.value;
        content.appendChild(this.text);

        this.waitcount = 50;
    }
    onExit(): void //离开状态
    {

    }

    getExitState(): number
    {
        if (this.waitcount <= 0)
            return 0;//0号出口
        return -1;//没处理完
    }

    onUpdate(): void//表达式计算
    {
        this.text.text = "当前块" + this.desc.name + "倒计时" + this.waitcount;
        this.waitcount--;
    }

    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "myblock7";
        desc.exitNames = ["出口0", "出口1", "出口2", "出口3"];
        desc.inParamNames = ["number", "name", "number"];
        desc.inParamTypes = ["integer", "string", "stirng"];
        desc.outParamNames = ["number", "number", "number"];
        desc.outParamTypes = ["integer", "integer", "integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new MyBlock2(); } });
    }
}
class MyBlock8 implements lighttool.tsbb.IBBAction_Flow
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0];
    }
    getOutParamValue(index: number): any
    {
        return null;
    }
    getOutParamValues(): any[]
    {
        return [];
    }

    //行为组
    waitcount: number = 0;
    text: HTMLAnchorElement;
    value: number = 0;
    onInit(): void //进入状态
    {
        var content = document.getElementById("content");

        var text2 = document.createElement("a");
        text2.text = " 我需要参数100:" + this.value;
        content.appendChild(text2);

        this.text = document.createElement("a");
        this.text.text = "  当前块" + this.desc.name + " 我需要参数100:" + this.value;
        content.appendChild(this.text);

        this.waitcount = 50;
    }
    onExit(): void //离开状态
    {

    }

    getExitState(): number
    {
        if (this.waitcount <= 0)
            return 0;//0号出口
        return -1;//没处理完
    }

    onUpdate(): void//表达式计算
    {
        this.text.text = "当前块" + this.desc.name + "倒计时" + this.waitcount;
        this.waitcount--;
    }

    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "myblock8";
        desc.exitNames = ["出口0", "出口1", "出口2", "出口3"];
        desc.inParamNames = ["number", "name", "number"];
        desc.inParamTypes = ["integer", "string", "stirng"];
        desc.outParamNames = ["number", "number", "number"];
        desc.outParamTypes = ["integer", "integer", "integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new MyBlock2(); } });
    }
}
class addOne implements lighttool.tsbb.IBBAction_Expr
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value + 1;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0] + 1;
    }
    getOutParamValue(index: number): any
    {
        if (index == 0)
            return this.value;
    }
    getOutParamValues(): any[]
    {
        return [this.value];
    }

    getReturnType(indata: any[]): string
    {
        return "any";

    }
    //行为组
    value: number = null;
    run(): lighttool.tsbb.exprReturnValue
    {
        if (this.value == null)
            return lighttool.tsbb.exprReturnValue.InParamNotReady;
        else
            return lighttool.tsbb.exprReturnValue.Succ;
    }
    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "addone";
        desc.exitNames = [];
        desc.inParamNames = ["number"];
        desc.inParamTypes = ["integer"];
        desc.outParamNames = ["number"];
        desc.outParamTypes = ["integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new addOne(); } });
    }
}
class addTwo implements lighttool.tsbb.IBBAction_Expr
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value + 1;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0] + 1;
    }
    getOutParamValue(index: number): any
    {
        if (index == 0)
            return this.value;
    }
    getOutParamValues(): any[]
    {
        return [this.value];
    }

    getReturnType(indata: any[]): string
    {
        return "any";

    }
    //行为组
    value: number = null;
    run(): lighttool.tsbb.exprReturnValue
    {
        if (this.value == null)
            return lighttool.tsbb.exprReturnValue.InParamNotReady;
        else
            return lighttool.tsbb.exprReturnValue.Succ;
    }
    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "addtwo";
        desc.exitNames = [];
        desc.inParamNames = ["number"];
        desc.inParamTypes = ["integer"];
        desc.outParamNames = ["number"];
        desc.outParamTypes = ["integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new addOne(); } });
    }
}
class sumOne implements lighttool.tsbb.IBBAction_Expr
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value + 1;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0] + 1;
    }
    getOutParamValue(index: number): any
    {
        if (index == 0)
            return this.value;
    }
    getOutParamValues(): any[]
    {
        return [this.value];
    }

    getReturnType(indata: any[]): string
    {
        return "any";

    }
    //行为组
    value: number = null;
    run(): lighttool.tsbb.exprReturnValue
    {
        if (this.value == null)
            return lighttool.tsbb.exprReturnValue.InParamNotReady;
        else
            return lighttool.tsbb.exprReturnValue.Succ;
    }
    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "sumone";
        desc.exitNames = [];
        desc.inParamNames = ["number"];
        desc.inParamTypes = ["integer"];
        desc.outParamNames = ["number"];
        desc.outParamTypes = ["integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new addOne(); } });
    }
}
class sumTwo implements lighttool.tsbb.IBBAction_Expr
{
    desc: lighttool.tsbb.BBDesc;
    getDisplayName(): string
    {
        return this.desc.name;
    }

    //参数组
    setInParamValue(index: number, value: any): void
    {
        if (index == 0)
        {
            this.value = value + 1;
        }
    }
    setInParmaValues(values: any[]): void
    {
        this.value = values[0] + 1;
    }
    getOutParamValue(index: number): any
    {
        if (index == 0)
            return this.value;
    }
    getOutParamValues(): any[]
    {
        return [this.value];
    }

    getReturnType(indata: any[]): string
    {
        return "any";

    }
    //行为组
    value: number = null;
    run(): lighttool.tsbb.exprReturnValue
    {
        if (this.value == null)
            return lighttool.tsbb.exprReturnValue.InParamNotReady;
        else
            return lighttool.tsbb.exprReturnValue.Succ;
    }
    static reg()
    {
        var desc = new lighttool.tsbb.BBDesc();
        desc.name = "sumtwo";
        desc.exitNames = [];
        desc.inParamNames = ["number"];
        desc.inParamTypes = ["integer"];
        desc.outParamNames = ["number"];
        desc.outParamTypes = ["integer"];
        //注册块
        lighttool.tsbb.bbFactory.instance().regItem({ desc: desc, ctor: () => { return new addOne(); } });
    }
}
window.onload = () =>
{

    //获取背景div
    let background = document.getElementById("flowView");                     //获取 flowView div
    //background.style.position = "absolute";
    //background.style.overflow = "auto";
    background.style.height = "1000px";
    let playerView: Flow.views.PlayerView = new Flow.views.PlayerView(background);

    //注册块
    MyBlock.reg();
    MyBlock2.reg();
    MyBlock3.reg();
    MyBlock4.reg();
    MyBlock5.reg();
    MyBlock6.reg();
    MyBlock7.reg();
    MyBlock8.reg();
    addOne.reg();
    addTwo.reg();
    sumOne.reg();
    sumTwo.reg();

    var bplayer = new lighttool.tsbb.bbplayer();

    //连接流程块
    var myblock = bplayer.addBlock("myblock");
    var myblock2 = bplayer.addBlock("myblock2");
    var myblock3 = bplayer.addBlock("myblock3");
    var myblock4 = bplayer.addBlock("myblock4");
    var myblock5 = bplayer.addBlock("myblock5");
    var myblock6 = bplayer.addBlock("myblock6");
    var myblock7 = bplayer.addBlock("myblock7");
    var myblock8 = bplayer.addBlock("myblock8");
    var begin = bplayer.getBeginBlock();
    var end = bplayer.getEndBlock();

    begin.linkExitTo(0, myblock);
    myblock.linkExitTo(0, myblock2);
    myblock.linkExitTo(1, myblock4);
    myblock.linkExitTo(2, myblock3);
    myblock.linkExitTo(3, myblock4);
    myblock2.linkExitTo(0, myblock5);
    myblock3.linkExitTo(0, myblock8);
    myblock3.linkExitTo(1, myblock6);
    myblock3.linkExitTo(2, myblock7);
    myblock4.linkExitTo(0, myblock5);
    myblock5.linkExitTo(0, myblock3);
    myblock5.linkExitTo(1, myblock);
    myblock6.linkExitTo(0, myblock8);
    myblock7.linkExitTo(0, myblock4);
    myblock8.linkExitTo(0, end);

    //下面测试参数连接
    var test = 2;
    if (test == 1)
    {
        //将我的0号出参，连到myblock2的0号入参
        myblock.linkOutParamTo(0, myblock2, 0);
    }
    else
    {
        //添加一个加1的块
        var addone = bplayer.addBlock("addone");
        var addtwo = bplayer.addBlock("addtwo");
        var sumone = bplayer.addBlock("sumone");
        var sumtwo = bplayer.addBlock("sumtwo");
        myblock.linkOutParamTo(0, addone, 0);
        addtwo.linkOutParamTo(0, myblock, 0);
        addone.linkOutParamTo(0, myblock2, 0);

        myblock.linkOutParamTo(1, addtwo, 0);
        addtwo.linkOutParamTo(0, myblock2, 1);
        myblock2.linkOutParamTo(0, sumone, 0);
        myblock2.linkOutParamTo(1, sumtwo, 0);
        sumone.linkOutParamTo(0, myblock3, 0);
        sumtwo.linkOutParamTo(0, myblock7, 0);
    }

    //初始化流程
    playerView.initFlow(bplayer);
    var content = document.getElementById("content");

    {
        //排序按钮
        let btn = document.createElement("button");
        btn.textContent = "自动排列";
        btn.style.top = "200px";
        btn.style.left = "100px";
        btn.style.height = "100px";
        btn.style.width = "100px";
        content.appendChild(btn);

        btn.onclick = () =>
        {
            playerView.sortOrder();
        };

    }
    {
        //保存布局
        let btn = document.createElement("button");
        btn.textContent = "保存布局 data/save.json";
        btn.style.top = "200px";
        btn.style.left = "100px";
        btn.style.height = "100px";
        btn.style.width = "100px";
        content.appendChild(btn);

        btn.onclick = () =>
        {
            var str = JSON.stringify(bplayer.makeJson());
            localsave.save("data/save.json", localsave.file_str2blob(str));
        };

    }
    {
        //加载布局
        let btn = document.createElement("button");
        btn.textContent = "加载布局";
        btn.style.top = "200px";
        btn.style.left = "100px";
        btn.style.height = "100px";
        btn.style.width = "100px";
        content.appendChild(btn);

        btn.onclick = () =>
        {

            var req = new XMLHttpRequest();//ness
            req.open("GET", "data/save.json" + "?" + Math.random());
            req.onreadystatechange = () => 
            {
                if (req.readyState == 4) 
                {

                    if (req.status == 404)
                        throw new Error("onerr 404");//ness
                    else
                    {
                        var str = req.responseText;
                        bplayer.fromJson(JSON.parse(str));
                        playerView.update();//这个行为不对，没有刷新数据
                    }
                }
            };
            req.onerror = () => 
            {
                throw new Error("onerr in req:");//ness
            };
            req.send();

        };

    }
    {
        //开始流程
        let btn = document.createElement("button");
        btn.textContent = "开始流程";
        btn.style.top = "200px";
        btn.style.left = "100px";
        btn.style.height = "100px";
        btn.style.width = "100px";
        content.appendChild(btn);
        btn.onclick = () => {
            bplayer.start(0);
        };
    }

    {
        //开始流程
        let btn = document.createElement("button");
        btn.textContent = "暂停/继续";
        btn.style.top = "200px";
        btn.style.left = "100px";
        btn.style.height = "100px";
        btn.style.width = "100px";
        content.appendChild(btn);
        btn.onclick = () => {
            if (bplayer.isPlayerRun()) {
                bplayer.stop();
            } else {
                bplayer.start(bplayer.getCurBlock().id);
            }
        };
    }


};

